package bdsimple.impl.mysql;

import bdsimple.abstractfactory.AbstractFactoryDAO;
import bdsimple.dao.base.TarjetaMemoriaDAO;
import bdsimple.dao.base.TarjetaMemoriaVampiroDAO;
import bdsimple.dao.base.VampiroDAO;
import bdsimple.dto.base.TarjetaMemoriaDTO;
import bdsimple.dto.base.TarjetaMemoriaVampiroDTO;
import bdsimple.dto.base.VampiroDTO;
import dao.base.impl.BaseDTO;
import dao.base.impl.Reference;

public class TarjetaMemoriaVampiroDTOImpl extends BaseDTO implements
		TarjetaMemoriaVampiroDTO {

	public TarjetaMemoriaVampiroDTOImpl() {
		super(TarjetaMemoriaVampiroDAO.class);
	}

	// ---------------------------------------------------------------------------

	private final Reference<VampiroDTO> vampiroDTORef = //
	new Reference<VampiroDTO>();

	private final Reference<TarjetaMemoriaDTO> tarjetaMemoriaDTORef = //
	new Reference<TarjetaMemoriaDTO>();

	// ---------------------------------------------------------------------------

	@Override
	public Reference<VampiroDTO> getVampiroDTORef() {
		return vampiroDTORef;
	}

	public VampiroDTO getVampiroDTO() {
		if (vampiroDTORef.getRefValue() == null) {
			if (vampiroDTORef.getRefIdent() != 0) {
				try {

					// Lazy load the departmentDTORef
					VampiroDAO vampiroDAO = (VampiroDAO) AbstractFactoryDAO
							.getFactoryDAO(). //
							getDAO(VampiroDAO.class, connectionBean);

					vampiroDTORef.setRefValue( //
							(VampiroDTO) vampiroDAO.loadById(vampiroDTORef
									.getRefIdent()));

				} catch (Exception e) {
					e.printStackTrace();
					throw new RuntimeException(e);
				}
			}
		}

		return vampiroDTORef.getRefValue();
	}

	public void setVampiroDTORef(VampiroDTO vampiroDTORef) {
		this.vampiroDTORef.setRefValue(vampiroDTORef);
	}

	// ---------------------------------------------------------------------------

	@Override
	public Reference<TarjetaMemoriaDTO> getTarjetaMemoriaDTORef() {
		return tarjetaMemoriaDTORef;
	}

	public TarjetaMemoriaDTO getTarjetaMemoriaDTO() {
		if (tarjetaMemoriaDTORef.getRefValue() == null) {
			if (tarjetaMemoriaDTORef.getRefIdent() != 0) {
				try {

					// Lazy load the departmentDTORef
					TarjetaMemoriaDAO tarjetaMemoriaDAO = (TarjetaMemoriaDAO) AbstractFactoryDAO
							.getFactoryDAO(). //
							getDAO(TarjetaMemoriaDAO.class, connectionBean);

					tarjetaMemoriaDTORef.setRefValue( //
							(TarjetaMemoriaDTO) tarjetaMemoriaDAO
									.loadById(tarjetaMemoriaDTORef
											.getRefIdent()));

				} catch (Exception e) {
					e.printStackTrace();
					throw new RuntimeException(e);
				}
			}
		}

		return tarjetaMemoriaDTORef.getRefValue();
	}

	@Override
	public void setTarjetaMemoriaDTORef(TarjetaMemoriaDTO tarjetaMemoriaDTO) {
		this.tarjetaMemoriaDTORef.setRefValue(tarjetaMemoriaDTO);
	}

	// ---------------------------------------------------------------------------

}
